package com.hsy.sunflowerbao.base.store

import com.flux.action.RxAction
import com.flux.action.RxStoreChange
import com.flux.dispatcher.Dispatcher
import com.flux.store.RxStore
import com.hsy.sunflowerbao.base.action.ActionType
import com.hsy.sunflowerbao.base.action.Key

/**
 * 基础数据缓存
 * Created on 2017/12/5.
 *
 * @author Yang
 */
abstract class BaseStore(dispatcher: Dispatcher) : RxStore(dispatcher) {

    var needReLogin = false
    var msgRes = -1
    var msg = ""
    /**
     * 是否接受网络异常
     */
    var handleSuper = true

    override fun onRxAction(action: RxAction) {
        if (action.type == ActionType.HTTP_ERROR) {
            //数据变更，发出对应的Action，通知view刷新
            if (action.data.containsKey(Key.HTTP_ERROR_MSG_RES)) msgRes = action[Key.HTTP_ERROR_MSG_RES]
            else msg = action[Key.HTTP_ERROR_MSG]
            needReLogin = action[Key.NEED_LOGIN]
            postChange(RxStoreChange(ID, action.type, false))
        } else if (action.type == ActionType.UPLOAD_IMGS) {

        }
    }

    override var tag = javaClass.simpleName

    companion object {
        //设置ID，分类用
        val ID = "BaseStore"
    }
}